<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<html>
<head>
<title>List of Dict</title>

<%@include file="/WEB-INF/pages/common/head.jsp" %>

<!-- third party lib -->
<link rel="stylesheet" type="text/css" href="<%=root%>/plugin/flexigrid/css/flexigrid/flexigrid.css">
<script type="text/javascript" src="<%=root%>/plugin/flexigrid/flexigrid.js"></script>

<!-- my lib -->

<script type="text/javascript">
var dataGrid = null ;

window.onload=function (){
	var toolbar = [
	                {name :'添加',bclass:'add',onpress:toAdd},
	                {name :'修改',bclass:'edit',onpress:toEdit},
	                {name :'删除',bclass:'delete',onpress:doDelete},
	                {separator : true}
	               ] ;

    if (opener != null) {
    	toolbar[toolbar.length] = {name :'选取',bclass:'search',onpress:doSelect}
    }
    
    dataGrid = $("#dataGrid").flexigrid(
        {
            url: '<%=root%>/system/dict_list.action',
            dataType: 'xml',
            colModel : [
                {display: '<input type="checkbox" name="checkAll" onclick="checkIds(this)" />', name:"dict_id", width:30, sortable: false, formater:idsCheckboxes},
                {display: 'Code', name : 'code_', width : 100, sortable : true, align: 'center'},
                {display: 'Domain', name : 'domain_', width : 120, sortable : true, align: 'left'},
                {display: 'Name', name : 'name_', width : 180, sortable : true, align: 'left'},
                {display: 'id_', name : 'dict_id', width : 130, hide: true}
                ],
            buttons : toolbar,
            sortname: "name_",
            sortorder: "asc",
            usepager: true,
            title: '这个是我的测试表格',
            useRp: true,
            rp: 15,
            showTableToggleBtn: false,
            width: 900,
            //onSubmit: doList,
            height: 420,
            searchDivName: "searchFormDiv",
            searchFormName:"searchForm",
            rowIdName:"dict_id",
            recordXPath:"root datas Dict"
        }
    );

    /*  
    $('#sform').submit
    (
        function ()
            {
                $('#dataGrid').flexOptions({newp: 1}).flexReload();
                return false;
            }
    );                      
    */

    doList();

    //alert(getWindowParams("dictList")) ;
}

function doList() {
    
    //$("#dataGrid").flexOptions({params: $(searchForm).serializeArray()}).flexReload();
    dataGrid.flexReload() ;
    return true;
}

//var windowParams = getWindowParams(window.name) ;

function doSelect() {
	/*
    var ids = dataGrid.getSelectedIds() ;


    windowParams.onReturn(ids[0]) ;
    
    windowParams.windowMe.dialog("close");

    window.href = "" ;
*/
    if(isDefined(opener.gridWindowOnSelected)) {
        opener.gridWindowOnSelected(dataGrid.getSelectedRows()[0])
    }

    window.close() ;
}

var windowMe = null ;
function toAdd() {
    windowMe = openWindow({url:"<%=root%>/system/dict_form.action", name:"addDict", width:400, height:400}) ;
}

function toEdit() {
    var ids = dataGrid.getSelectedIds() ;
    
    if(ids.length==1){
        //alert(dataGrid.getSelectedRows()[0]);
        
        windowMe = openWindow({url:"<%=root%>/system/dict_form.action", name:"updateDict", width:400, height:400}) ;
        
    }else if(ids.length>1){
        alert("请选择一个修改,不能同时修改多个记录!");
    }else if(ids.length==0){
        alert("请选择一个您要修改的记录!")
    }
}

function doEditOnRetrun(xml) {
    doList();
    
    $('#dialogEdit').dialog("close");
}

function doDelete() {
    
    if (confirm("确定要删除数据吗？")) {
        $.post("/easyframe/system/dict_delete.action", $(searchForm).serialize(), doDeleteOnRetrun); 
    }

}

function doDeleteOnRetrun(xml) {
    doList();
}

function idsCheckboxes(value) {
    return "<input type='checkbox' value='" + value + "' name='ids' />" ;
}

function checkIds(checkboxAll) {
    var ids = document.all("ids") ;

    for (var i = 0 ; i < ids.length ; i ++) {
        ids[i].checked = checkboxAll.checked ;
    }
}

function formWindowOnClose(editForm) {
	doList() ;
}


window.onunload = function () {
	unblock();
}
</script>
</head>
<body topmargin="0" leftmargin="0">
  <form action="/easyframe/system/dict_list.action" method="post" name="searchForm" id="searchForm"  topmargin="0" leftmargin="0" >
    <input type="hidden" name="pageSize"/>
    
    <table id="dataGrid" style="display:none">
    </table>
    <div style="display: none">
    <div id="searchFormDiv">
          <table width="100%" style="margin-top: 4px">
              <tr valign="middle">
                 <td>domain:<input type="text" name="dict.domain_"/></td>
                 <td>code:<input type="text" name="dict.code_"/></td>
                 <td>name:<input type="text" name="dict.name_"/><select><option>sss</option></select></td>
               </tr>
          </table>
    </div>
    </div>
  </form>

  <!--             
    <div id="dialogEdit" title="添加" style="display: none">
      <form action="" method="post" name="editForm" id="editForm">
          <input type="hidden" name="dict.dict_id"/>
          <table>
              <tr><td>domain_:</td></tr>
              <tr><td><input type="text" name="dict.domain_"/><input type="button" value="getDict" onclick="getDict()" /></td></tr>
              <tr><td>code:</td></tr>
              <tr><td><input type="text" name="dict.code_"/></td></tr>
              <tr><td>name:</td></tr>
              <tr><td><input type="text" name="dict.name_"/></td></tr>
          </table>
      </form>
    </div>
   -->
</body>
</html>